import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        String[] role = new String[5];
        boolean[] state = new boolean[5];
        initInfo(role, state);
        System.out.println("欢迎来到狼人杀游戏！");
        while (true) {
            printInfo(role, state);
            wolfPlay(role, state);
            char ret;
            ret = isWin(role, state);
            if(ret=='*')
            {
                System.out.println("狼人胜利！");
                System.out.println("游戏结束，再见!");
                break;
            }
            if(ret=='#')
            {
                System.out.println("平民胜利");
                System.out.println("游戏结束，再见!");
                break;
            }
            peoPlay(state);
            ret = isWin(role, state);
            if(ret=='*')
            {
                System.out.println("狼人胜利！");
                System.out.println("游戏结束，再见!");
                break;
            }
            if(ret=='#')
            {
                System.out.println("平民胜利");
                System.out.println("游戏结束，再见!");
                break;
            }
        }

    }

    public static void wolfPlay(String[] role, boolean[] state){
        Scanner scan = new Scanner(System.in);
        System.out.println("狼人请行动（输入你要杀死的玩家编号）");
        int i = scan.nextInt();
        if(role[i].equals("狼人")) {
            System.out.println("杀死同伴无效");
        }
        else
        {
            state[i] = false;
            System.out.println("玩家"+i+"被杀死");
        }
    }

    public static void peoPlay(boolean[] state){
        Scanner scan = new Scanner(System.in);
        System.out.println("平民请行动(输入你要投票的玩家编号");
        int i = scan.nextInt();
        state[i] = false;
        System.out.println("玩家"+i+"被杀死");
    }
    public static char isWin(String[] role, boolean[] state){
        int countWolf = 0;
        int countPeo = 0;
        for (int i = 0; i < role.length; i++) {
            if(state[i]&&role[i].equals("狼人"))
            {
                countWolf++;
            }
            if(state[i]&&role[i].equals("平民"))
            {
                countPeo++;
            }
        }
        if(countWolf>=countPeo)
            return '*';
        else if(countWolf==0)
            return '#';
        else
            return 'c';
    }

    public static void printInfo(String[] role, boolean[] state){
        System.out.println("当前存活玩家：");
        for (int i = 0; i < role.length; i++) {
            if(state[i])
            {
                System.out.println(i+":"+role[i]);
            }
        }
    }
    public static void initInfo(String[] role, boolean[] state) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请为游戏输入几个角色的名字：");
        for (int i = 0; i < role.length; i++) {
            System.out.println("角色"+i+":");
            role[i] = scan.nextLine();
        }
        Arrays.fill(state, true);
    }
}
